/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ohos.bluetooth.base_profile
import ohos.callback_invoke.{ Callback1Argument, CallbackObject}
import ohos.bluetooth.constant.ProfileConnectionState
import ohos.labels.APILevel
import std.deriving.Derive


/**
* Enum for cause of disconnect.
*
* @relation enum DisconnectCause
*/
@Derive[ToString, Equatable]
@!APILevel[
    22,
    syscap: "SystemCapability.Communication.Bluetooth.Core"
]
public enum DisconnectCause {
    /**
    * User disconnect device.
    *
    * @relation USER_DISCONNECT = 0
    */
    @!APILevel[
        22,
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    UserDisconnect |
    /**
    * The connection needs to be initiated from the keyboard side.
    *
    * @relation CONNECT_FROM_KEYBOARD = 1
    */
    @!APILevel[
        22,
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    ConnectFromKeyboard |
    /**
    * The connection needs to be initiated from the mouse side.
    *
    * @relation CONNECT_FROM_MOUSE = 2
    */
    @!APILevel[
        22,
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    ConnectFromMouse |
    /**
    * The connection needs to be initiated from the car side.
    *
    * @relation CONNECT_FROM_CAR = 3
    */
    @!APILevel[
        22,
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    ConnectFromCar |
    /**
    * Too many devices are currently connected.
    *
    * @relation TOO_MANY_CONNECTED_DEVICES = 4
    */
    @!APILevel[
        22,
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    TooManyConnectedDevices |
    /**
    * Connection failed due to an internal error.
    *
    * @relation CONNECT_FAIL_INTERNAL = 5
    */
    @!APILevel[
        22,
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    ConnectFailInternal |
    ...
}



/**
* Profile state change parameters.
*
* @relation export interface StateChangeParam
*/
@!APILevel[
    22,
    syscap: "SystemCapability.Communication.Bluetooth.Core"
]
public class StateChangeParam {
    /**
    * The address of device.
    *
    * @relation deviceId: string
    */
    @!APILevel[
        22,
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    public var deviceId: String
    
    /**
    * Profile state value.
    *
    * @relation state: ProfileConnectionState
    */
    @!APILevel[
        22,
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    public var state: ProfileConnectionState
    
    /**
    * Cause of disconnect.
    *
    * @relation cause: DisconnectCause
    */
    @!APILevel[
        22,
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    public var cause: DisconnectCause
}


/**
* Base interface of profile.
*
* @relation interface BaseProfile
*/
@!APILevel[
    22,
    syscap: "SystemCapability.Communication.Bluetooth.Core"
]
public interface BaseProfile {
    /**
    * Get connection strategy of this profile.
    *
    * @throws { BusinessException } 201 - Permission denied.
    * @throws { BusinessException } 801 - Capability not supported.
    * @throws { BusinessException } 2900001 - Service stopped.
    * @throws { BusinessException } 2900003 - Bluetooth disabled.
    * @throws { BusinessException } 2900004 - Profile not supported.
    * @throws { BusinessException } 2900099 - Operation failed.
    * @relation getConnectedDevices(): Array<string>
    */
    @!APILevel[
        22,
        permission: "ohos.permission.ACCESS_BLUETOOTH",
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    func getConnectedDevices(): Array<String>
    
    /**
    * Obtains the profile connection state.
    *
    * @throws { BusinessException } 201 - Permission denied.
    * @throws { IllegalArgumentException } - Invalid parameter, Parameter verification failed.
    * @throws { BusinessException } 801 - Capability not supported.
    * @throws { BusinessException } 2900001 - Service stopped.
    * @throws { BusinessException } 2900003 - Bluetooth disabled.
    * @throws { BusinessException } 2900004 - Profile not supported.
    * @throws { BusinessException } 2900099 - Operation failed.
    * @relation getConnectionState(deviceId: string): ProfileConnectionState
    */
    @!APILevel[
        22,
        permission: "ohos.permission.ACCESS_BLUETOOTH",
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    func getConnectionState(deviceId: String): ProfileConnectionState
    
    /**
    * Subscribe the event reported when the profile connection state changes.
    *
    * @throws { BusinessException } 201 - Permission denied.
    * @throws { IllegalArgumentException } - Invalid parameter, Parameter verification failed.
    * @throws { BusinessException } 801 - Capability not supported.
    * @relation on(type: 'connectionStateChange', callback: Callback<StateChangeParam>): void
    */
    @!APILevel[
        22,
        permission: "ohos.permission.ACCESS_BLUETOOTH",
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    func on(eventType: ProfileCallbackType, callback: Callback1Argument<StateChangeParam>): Unit
    
    /**
    * Unsubscribe the event reported when the profile connection state changes.
    *
    * @throws { BusinessException } 201 - Permission denied.
    * @throws { IllegalArgumentException } - Invalid parameter, Parameter verification failed.
    * @throws { BusinessException } 801 - Capability not supported.
    * @relation off(type: 'connectionStateChange', callback?: Callback<StateChangeParam>): void
    */
    @!APILevel[
        22,
        permission: "ohos.permission.ACCESS_BLUETOOTH",
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    func off(eventType: ProfileCallbackType, callback: CallbackObject): Unit
    
    /**
    * Unsubscribe the event reported when the profile connection state changes.
    *
    * @throws { BusinessException } 201 - Permission denied.
    * @throws { IllegalArgumentException } - Invalid parameter, Parameter verification failed.
    * @throws { BusinessException } 801 - Capability not supported.
    * @relation off(type: 'connectionStateChange', callback?: Callback<StateChangeParam>): void
    */
    @!APILevel[
        22,
        permission: "ohos.permission.ACCESS_BLUETOOTH",
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    func off(eventType: ProfileCallbackType): Unit
}


/**
* Type of the profile connection state changes event to listen for.
*/
@Derive[ToString, Hashable, Equatable]
@!APILevel[
    22,
    syscap: "SystemCapability.Communication.Bluetooth.Core"
]
public enum ProfileCallbackType {
    /**
    * Connection State Change.
    */
    @!APILevel[
        22,
        syscap: "SystemCapability.Communication.Bluetooth.Core"
    ]
    ConnectionStateChange |
    ...
}



